<include file="header"/>
<body>
    <div class="wraper hasmenu">
        <div class="head clearfix">
            <if condition="$hiddenNav eq 1">
                <a href="{BEESCRM::U('/Charger/ChargingproxWd/index',array('accountId'=>$accountId,'chargingId'=>$chargingId))}" class="iconfont icon-zuo pull-left"></a>
                <span class="head-name pull-left">正在充电</span>
                <else/>
                <a href="javascript:" class="iconfont" style="width:100%;text-align:center">正在充电</a>
            </if>
            
        </div>
        <div class="lists">
            <div class="list-line">
                <div class="charing-img"><img src="/assets/charger/images/charging.gif"/></div>
                <p class="text-green">正在充电...</p>
            </div>
            <div  class="list-line text-12">
                <p>当前位置：{BEESCRM:$websiteInfo.website_name} | {BEESCRM:$terminalInfo['line_num']}号充电桩</p>
                <p>开始时间：{BEESCRM:$data.start_time|date='Y-m-d H:i:s',###}</p>
                <p>计划充电时长：{BEESCRM:$data.freezing_time}分钟</p>
                <p>已充电时长：<font id="charging-time">00小时 00分 00秒</font></p>
            </div>
        </div>
        <div class="banner">
            <div class="swiper-container">
                <div class="swiper-wrapper">
                    <volist name="adInfo" id="vo">
                        <div class="swiper-slide"><a href="{BEESCRM:$vo.url}">{BEESCRM:$vo.content}</a></div>
                    </volist>
                </div>

                <div class="swiper-pagination"></div>

            </div>
        </div>
        <div class="btn-box">
            <a href="#" class="btn end-btn">结束充电</a>
            <if condition="$chargingId eq 32">
                <div class="list-line text-12 text-grey" style="margin-top:10px">客服电话:深圳市广巨德科技有限公司<a href="tel:15013440251">15013440251</a>
                </div>
            </if>
        </div>

        <if condition="$hiddenNav neq 1">
            <include file="nav"/>
        </if>
    </div>
    <include file="commonJS" />
    <script>
        seajs.use(['$','swiper'], function(main,swiper,layer) {

            console.log({BEESCRM:$hiddenNav});
            $(function(){
        /*var swiper = new Swiper('.banner .swiper-container', {
//            pagination: '.banner .swiper-pagination',
            paginationClickable: true,
            spaceBetween: 30,
            centeredSlides: true,
            autoplay: 2500,
            autoplayDisableOnInteraction: false,
            loop: true
        });*/


        $(window).load(function(){
            $('.load').hide();
        });

        
        var startTime = "{BEESCRM:$data.start_time}000";

        (function timer() {
            timeDiff(startTime);
            setTimeout(function () {
                timer();
            }, 1000);
        })();

        function timeDiff(startTime) {
            var diffTime = $.now() - startTime;

            var hour = Math.floor(diffTime/(3600*1000));

            var minutes = Math.floor((diffTime - hour*60*60*1000)/(60*1000));

            var seconds = Math.floor((diffTime - hour*60*60*1000 - minutes*60*1000)/1000);

            $('#charging-time').text(('0' + hour).slice(-3) + '小时 ' + ('0' + minutes).slice(-2) + '分 ' + ('0' + seconds).slice(-2) + '秒 ');

        }
        
        $(document).on('click','.end-btn',function(){


            fm.confirm('是否结束本次充电',function(callback){
                if(callback==1){
                    drop();
                }
            })
            
            
            
            function drop(){
                var data={};
                data.charging_log_id="{BEESCRM:$data.charging_log_id}";
                //layer.msg(data.charging_log_id);return;
                if(!data.charging_log_id){
                    //$.alert('error','参数错误');return;
                }
                $.ajax({
                    url:"{BEESCRM::U('/Charger/ChargingproxWd/switchOff',array('accountId'=>$accountId,'chargingId'=>$chargingId))}",
                    type:"post",
                    data:data,
                    dataType:'json',
                    beforeSend: function(){
                        fm.showLoging('充电结束处理中,请稍后...');
                    },
                    success:function(res){
                        fm.closeLayer(3);
                        if(res.status=='S'){
                            reload();
                        }else{
                            fm.alert(res.message,'',3);
                        }
                    },
                    error:function(res){
                        fm.alert(res.message,'',3);
                    }
                })
            }
            function reload(){
                setTimeout('location.href="{BEESCRM::U('/Charger/ChargingproxWd/index',array('accountId'=>$accountId,'chargingId'=>$chargingId))}"',1);
            }
        });
        
        var A=setInterval(function(){
            var data={};
            var json={};
            data.charging_log_id="{BEESCRM:$logInfo.charging_log_id}";

            $.ajax({
                url:"{BEESCRM::U('/Charger/ChargingproxWd/checkCharge',array('accountId'=>$accountId,'chargingId'=>$chargingId))}",
                type:"post",
                data:data,
                dataType:"json",
                success:function(res){
                    update(res);
                }
            })
        },10000);
        function update(data){
            var status=data.status;
            if(status=='S'){
                setTimeout('location.href="{BEESCRM::U('/Charger/ChargingproxWd/index',array('accountId'=>$accountId,'chargingId'=>$chargingId))}"',3000);
            }
        }

    })
        });

    </script>
</body>
</html>
